﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;
using System.IO;

namespace RapChieuPhim
{
    public partial class PhimChieu : Form
    {
        PhimChieuBUS pcbus = new PhimChieuBUS();
        DataTable dt = new DataTable();
    
        public PhimChieu()
        {
            InitializeComponent();
        }
  
     
       



        private void PhimChieu_Load(object sender, EventArgs e)
        {
            cbxPhimDangChieu.DataSource = pcbus.LayDanhSachPhimDangChieu();
            cbxPhimDangChieu.DisplayMember = "TenPhim";
            cbxPhimDangChieu.ValueMember = "MaPhim";
            grbThongTinPhimDC.Visible = false;

            cbxPhimSapChieu.DataSource = pcbus.LayDanhSachPhimSapChieu();
            cbxPhimSapChieu.DisplayMember = "TenPhim";
            cbxPhimSapChieu.ValueMember = "MaPhim";
            grbThongTinPhimSC.Visible = false;

            cbxDSPhimDaChieu.DataSource = pcbus.LayDanhSachPhimDaChieu();
            cbxDSPhimDaChieu.DisplayMember = "TenPhim";
            cbxDSPhimDaChieu.ValueMember = "MaPhim";
            grbThongTinPhimĐC.Visible = false;
        }

        private void btnThongTinPhim_Click(object sender, EventArgs e)
        {
            grbThongTinPhimDC.Visible = true;
            if (cbxPhimDangChieu.SelectedValue.ToString() == null)
                {
                    MessageBox.Show("Vui lòng chọn phim cần xem thông tin","Thông báo",MessageBoxButtons.OK,MessageBoxIcon.Warning);

                }
                else
                {
                    string maPhim = cbxPhimDangChieu.SelectedValue.ToString();
                    dt = pcbus.LayThongTinPhimTheoMa(maPhim);
                    for (int i = 0; i <= dt.Rows.Count; )
                    {
                        DataRow dr = dt.Rows[i];
                        lbDSDienVien.Text = dr[0].ToString();
                        lbTheLoai.Text = dr[1].ToString();
                        lbDinhDang.Text = dr[2].ToString();
                        lbNuocSX.Text = dr[3].ToString();
                        lbNgayBD.Text = dr[4].ToString();
                        lbNgayKT.Text = dr[5].ToString();
                        //string img = @"..\..\Resources\Images\"+dr[6].ToString();
                        //pcbxPhim.BackgroundImage = System.Drawing.Image.FromFile(img);

                        Image img = Image.FromFile( @"..\..\Resources\Images\"+dr[6].ToString());        
                        pcbxPhim.Image = img;
                        pcbxPhim.Height = pcbxPhim.Height;
                        pcbxPhim.Width = pcbxPhim.Width;

                        return;
                      
                    }
                   
                }
            
        }

        private void btnThongTinPhimSapChieu_Click(object sender, EventArgs e)
        {
            grbThongTinPhimSC.Visible = true;
            if (cbxPhimSapChieu.SelectedValue.ToString() == null)
            {
                MessageBox.Show("Vui lòng chọn phim cần xem thông tin", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);

            }
            else
            {
                string maPhim = cbxPhimSapChieu.SelectedValue.ToString();
                dt = pcbus.LayThongTinPhimTheoMa(maPhim);
                for (int i = 0; i <= dt.Rows.Count; )
                {
                    DataRow dr = dt.Rows[i];
                    lbDVPhimSC.Text = dr[0].ToString();
                    lbTheLoaiPhimSC.Text = dr[1].ToString();
                    lbDinhdangPhimSC.Text = dr[2].ToString();
                    lbNuocSXPhimSC.Text = dr[3].ToString();
                    lbNgayBDPhimSC.Text = dr[4].ToString();
                    lbNgayKTPhimSC.Text = dr[5].ToString();
                    //string img = @"..\..\Resources\Images\"+dr[6].ToString();
                    //pcbxPhim.BackgroundImage = System.Drawing.Image.FromFile(img);

                    Image img = Image.FromFile(@"..\..\Resources\Images\" + dr[6].ToString());
                    pcbPhimSapChieu.Image = img;
                    pcbPhimSapChieu.Height = pcbPhimSapChieu.Height;
                    pcbPhimSapChieu.Width = pcbPhimSapChieu.Width;

                    return;
                   
                }

            }
        }

        private void btnThongTinPhimDC_Click(object sender, EventArgs e)
        {
            grbThongTinPhimĐC.Visible = true ;
            if (cbxDSPhimDaChieu.SelectedValue.ToString() == null)
            {
                MessageBox.Show("Vui lòng chọn phim cần xem thông tin", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);

            }
            else
            {
                string maPhim = cbxDSPhimDaChieu.SelectedValue.ToString();
                dt = pcbus.LayThongTinPhimTheoMa(maPhim);
                for (int i = 0; i <= dt.Rows.Count; )
                {
                    DataRow dr = dt.Rows[i];
                    lbDVPhimDC.Text = dr[0].ToString();
                    lbTheLoaiPhimDC.Text = dr[1].ToString();
                    lbDinhDangPhimDC.Text = dr[2].ToString();
                    lbNuocSXPhimDC.Text = dr[3].ToString();
                    lbNgayBDPhimDC.Text = dr[4].ToString();
                    lbNgayKTPhimDC.Text = dr[5].ToString();
                    //string img = @"..\..\Resources\Images\"+dr[6].ToString();
                    //pcbxPhim.BackgroundImage = System.Drawing.Image.FromFile(img);

                    Image img = Image.FromFile(@"..\..\Resources\Images\" + dr[6].ToString());
                    pcbPhimDaChieu.Image = img;
                    pcbPhimDaChieu.Height = pcbPhimDaChieu.Height;
                    pcbPhimDaChieu.Width = pcbPhimDaChieu.Width;

                    return;
                    grbThongTinPhimĐC.Visible = true;
                }

            }
        }

    
     
    }
}
